var t = require("../../api.js"), a = getApp();

Page({
    data: {
        keyword: !1,
        user_list: [],
        show_result: !1,
        is_search: !0,
        deputy_info:''
    },
    onLoad: function(t) {
        a.pageOnLoad(this, t);
        this.onloadData(t);
    },
    onloadData: function (r) {
      var a = this;
      wx.showLoading({
        title: "正在加载",
        mask: !0
      }), getApp().request({
        url: t.commander.get_info,
        success: function (t) {
          a.setData({
            deputy_info: t.data.deputy_info
          })

        },
        complete: function () {
          wx.hideLoading();
        }
      });
    },
    inputConfirm: function(t) {
        var a = this, s = t.detail.value;
        0 != s.length && (a.setData({
            keyword: s
        }),a.getUserList());
    },
  
    getUserList: function() {
        var s = this;
        wx.showLoading({
          title: '加载中',
        })
        a.request({
            url: t.default.get_user,
            data: {'keyword':s.data.keyword},
            success: function(t) {
                s.setData({
                  show_result: !0
                });

                0 == t.code && (s.setData({
                    user_list: t.data.list
                }), 0 == t.data.list.length ? s.setData({
                    is_search: !1
                }) : s.setData({
                    is_search: !0
                })), t.code;
            },
            complete: function () {
              wx.hideLoading()
            }
        });
    },

    addDeputy:function(e){
      var id = e.currentTarget.dataset['id'];
      var name = e.currentTarget.dataset['name'];
      wx.showModal({
        title: '提示',
        content: '是否将'+name+'设为副团长',
        success: function (res) {
          if (res.confirm) {
            wx.showLoading({
              title: '加载中',
            })
            a.request({
              url: t.default.set_deputy,
              data: { 'id': id },
              success: function (t) {
                if (0 == t.code){
                  wx.navigateBack({
                    delta: 1
                  })
                }else{
                  wx.showToast({
                    icon: "none",
                    title: t.data
                  });
                }
              },
              complete:function () {
                wx.hideLoading()
              }
            });
          }
        }
      })
    },

    delDeputy: function (ee) {
      var id = 0;
      var that = this;
      wx.showModal({
        title: '提示',
        content: '是否删除副团长',
        success: function (res) {
          if (res.confirm) {
            getApp().request({
              url: t.default.del_deputy,
              data: { 'id': id },
              success: function (t) {
                if (0 == t.code) {
                  that.setData({
                    deputy_info: ''
                  })
                } else {
                  wx.showToast({
                    icon: "none",
                    title: t.data
                  });
                }
              },
            });
          }
        }
      })
    },
    onShow: function () {
      getApp().pageOnShow(this);
      var t = this;
      wx.setNavigationBarTitle({ 
        title: '添加副' + t.data.store.tz_name
      })
    }
   
});